var vm = new Vue({
    el: "#app",
    data: {
        expires: [20],
        rates: [{
            name: "基准利率4.90%上限1.20倍",
            value: 0.049 * 1.20
        }, {
            name: "基准利率4.90%上限1.15倍",
            value: 0.049 * 1.15
        }, {
            name: "基准利率4.90%上限1.10倍",
            value: 0.049 * 1.10
        }, {
            name: "基准利率4.90%上限1.05倍",
            value: 0.049 * 1.05
        }, {
            name: "最新基准利率4.90%",
            value: 0.049
        }, {
            name: "基准利率4.90%下限95折",
            value: 0.049 * 0.95
        }, {
            name: "基准利率4.90%下限90折",
            value: 0.049 * 0.90
        }, {
            name: "基准利率4.90%下限85折",
            value: 0.049 * 0.85
        }, {
            name: "基准利率4.90%下限80折",
            value: 0.049 * 0.80
        }, {
            name: "基准利率4.90%下限75折",
            value: 0.049 * 0.75
        }, {
            name: "基准利率4.90%下限70折",
            value: 0.049 * 0.70
        }],
        ways: [{
            name: "等额本息",
            value: 0
        }, {
            name: "等额本金",
            value: 1
        }],
        options: {
            money: "",
            expire: "",
            rate: "",
            rateName: "",
            way: ""
        },

        results: {
            payMonth: "",
            totalInterest: "",
            sum: ""
        },

        i: 0
        // isA: true,
        // isB: false,
        // isC: false
    },
    methods: {
        // active: function (str) {
        //     switch (str) {
        //         case "a":
        //             {
        //                 this.isA = true;
        //                 this.isB = false;
        //                 this.isC = false;
        //                 break;
        //             }
        //         case "b":
        //             {
        //                 this.isA = false;
        //                 this.isB = true;
        //                 this.isC = false;
        //                 break;
        //             }
        //         case "c":
        //             {
        //                 this.isA = false;
        //                 this.isB = false;
        //                 this.isC = true;
        //                 break;
        //             }
        //         default:
        //             ;
        //     }
        // },
        clear: function () {
            for (var i in this.options) {
                this.options[i] = "";
            }
            for (var j in this.results) {
                this.results[j] = "";
            }
            this.i = 0;
        },
        calc: function () {
            var type = this.options.way, // 还款方式 0：等额本息还款 1：等额本金还款
                rate = this.options.rate / 12, // 月利率
                month = this.options.expire, // 贷款月数
                money = parseFloat(this.options.money) * 10000; // 本金

            var payMonth = 0, // 月供金额
                totalInterest = 0, // 总利息
                sum = 0; // 本息合计
            // 等额本息还款
            if (type === 0) {
                payMonth = money * rate * Math.pow(1 + rate, month) / (Math.pow(1 + rate, month) - 1);
                totalInterest = month * payMonth - money;
                sum = month * payMonth;
            }
            // 等额本金还款
            else if (type === 1) {
                var paid = money / month * this.i++;
                payMonth = money / month + (money - paid) * rate;
                totalInterest = (month + 1) * money * rate / 2;
                sum = totalInterest + money;
            }

            this.results.payMonth = payMonth.toFixed(2);
            this.results.totalInterest = totalInterest.toFixed(2);
            this.results.sum = sum.toFixed(2);
        },
        clearResult: function () {
            for (var i in this.results) {
                this.results[i] = "";
            }
            this.i = 0;
        }
    }
});